# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=pycurl
pkgbase=mingw-w64-python-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-python-${_realname}
pkgver=7.44.1
pkgrel=2
pkgdesc='A Python 3.x interface to libcurl (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('MIT')
url='https://github.com/pycurl/pycurl'
depends=(${MINGW_PACKAGE_PREFIX}-python
         ${MINGW_PACKAGE_PREFIX}-curl)
makedepends=(${MINGW_PACKAGE_PREFIX}-python-setuptools
             "${MINGW_PACKAGE_PREFIX}-cc")
source=(https://github.com/pycurl/${_realname}/archive/REL_7_44_1.tar.gz
        001-pycurl-setup-fix.patch)
sha256sums=('9dfc8bb1c1bd2ad9194336e7b263afe513cbc468a669a269ee4a9a852019c3a3'
            'cd2ea373f576b35967f99e6e183a92faf3fb0908456be2157cbf4ec44ba648d8')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-REL_7_44_1" "python-build-${MSYSTEM}"

  cd "python-build-${MSYSTEM}"
  patch -p1 -i ${srcdir}/001-pycurl-setup-fix.patch
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python setup.py build --with-openssl \
    --curl-config=${MINGW_PREFIX}/bin/curl-config
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 COPYING-MIT "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
